#为了方便，先初始化userinfo
import json
# d = {'username':'admin','password':'123456','usertype':0}
# d_json = json.dumps(d)
# print(d_json)
# 得出字典
class Client:
    def __init__(self):
        self.userinfo == None
    def startup(self): #启动
        # print('我启动了')
        self.login()
        if self.userinfo.usertype == 0:
            self.admin_client()
        else:
            self.stu_client()

    def admin_client():
        # print('管理员登陆了')
        while True:
            menu = ("创建学生",'','','')
            for i in range(len(menu)):
                print(i+1,menu[i])
            choice = input('请输入你要执行的菜单：')
            if choice == '1':
                # 让管理员去添加学生
                # 管理员对象
                self.userinfo.create 
            elif choice == '2':
                pass
            elif choice == '3':
                pass
            elif choice == '4':
                pass
            elif choice == '5':
                break
    def stu_client():
        print('学生登陆了')

    def login(self): #写一个登陆功能
        # 输入用户名和密码
        username = input('请输入用户名')
        password = input('请输入密码')
        # print('登录')
        with open(r'userinfo.txt',mode='r',encoding='utf-8') as f:
            for line in f:
                d = json.loads(line)
                if username == d['username'] and password == d['password']:
                    print('登陆成功')
                    if d ['usertype'] == 0:
                        self.userinfo = Admin(d['username'],d['password'],d['usertype'])#'管理员对象'---》'管理员类'
                    else:
                        self.userinfo = self.userinfo = Student(d['username'],d['password'],d['usertype'],d['cour_list'])#'学生对象' --》'学生类'

                    # 判断这个人是管理员还是
                    return
            else:
                print('登录成功')

class Admin:
    def __init__(self,username,password,usertype):
        self.username = username
        self.password = password
        self.usertype = usertype        

class Student:
    def __init__(self,username,password,usertype,cour_list=None):
        self.username = username
        self.password = password
        self.usertype = usertype
        self.cour_list = cour_list if cour_list else [] #[1,2,3]课程列表              
    


if __name__ == '__main__':
    # Client().startup()
    c = Client()
    c.startup()